#课堂练习
# #将球移动到指定位置，并且将原位置的球使用一个和背景颜色相同的矩形块覆盖掉
# import pygame,sys
# pygame.init()
# screen=pygame.display.set_mode([640,480])
# screen.fill([255,255,255])
# my_ball=pygame.image.load("Image\\beach_ball.png")
# screen.blit(my_ball,[50,50])
# pygame.display.flip()
# pygame.time.delay(2000) #延迟2秒
# screen.blit(my_ball,[150,50])   #在新位置绘制球图片
# pygame.draw.rect(screen,[255,255,255],[50,50,90,90],0)  #使用一个新的矩形覆盖原来位置（相当于擦除第一个位置的球图片）
# pygame.display.flip()
# while True:
#     for event in pygame.event.get():
#         if event.type==pygame.QUIT:
#             sys.exit()

# #移动球
# import pygame,sys
# pygame.init()
# screen=pygame.display.set_mode([640,480])
# screen.fill([255,255,255])
# my_ball=pygame.image.load("Image\\beach_ball.png")
# x=50
# y=50
# screen.blit(my_ball,[x,y])
# pygame.display.flip()
# for looper in range(1,200):
#     pygame.time.delay(20)
#     pygame.draw.rect(screen,[255,255,255],[x,y,90,90],0)
#     x=x+5
#     screen.blit(my_ball,[x,y])
#     pygame.display.flip()

# while True:
#     for event in pygame.event.get():
#         if event.type==pygame.QUIT:
#             sys.exit()

# #移动球（在水平方向上来回移动）
# import pygame,sys
# pygame.init()
# screen=pygame.display.set_mode([640,480])
# screen.fill([255,255,255])
# my_ball=pygame.image.load("Image\\beach_ball.png")
# x=50
# y=50
# x_speed=10

# while True:
#     for event in pygame.event.get():
#         if event.type==pygame.QUIT:
#             sys.exit()

#     pygame.time.delay(20)
#     pygame.draw.rect(screen,[255,255,255],[x,y,90,90],0)
#     x=x+x_speed
#     if x>screen.get_width()-90 or x<0:  #当球碰到窗口的任意一边
#         x_speed=-x_speed
#     screen.blit(my_ball,[x,y])
#     pygame.display.flip()

# #移动球（在水平、垂直方向上移动）
# import pygame,sys
# pygame.init()
# screen=pygame.display.set_mode([640,480])
# screen.fill([255,255,255])
# my_ball=pygame.image.load("Image\\beach_ball.png")
# x=50
# y=50
# x_speed=10
# y_speed=10

# while True:
#     for event in pygame.event.get():
#         if event.type==pygame.QUIT:
#             sys.exit()

#     pygame.time.delay(20)
#     pygame.draw.rect(screen,[255,255,255],[x,y,90,90],0)
#     x=x+x_speed
#     y=y+y_speed
#     if x>screen.get_width()-90 or x<0:  #当球碰到窗口的任意一边
#         x_speed=-x_speed
#     if y>screen.get_height()-90 or y<0:
#         y_speed=-y_speed
#     screen.blit(my_ball,[x,y])
#     pygame.display.flip()


#利用翻转移动沙滩球图像
import pygame,sys
pygame.init()
screen=pygame.display.set_mode([640,480])
screen.fill([255,255,255])
my_ball=pygame.image.load("Image\\beach_ball.png")
x=50
y=50
x_speed=5

while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            sys.exit()

    pygame.time.delay(20)
    pygame.draw.rect(screen,[255,255,255],[x,y,90,90],0)
    x=x+x_speed
    if x>screen.get_width()-90 or x<0:  #当球碰到窗口的任意一边
        x=90
    screen.blit(my_ball,[x,y])
    pygame.display.flip()
